#include <iostream>
#include <array>
#include <memory>

#include "Timer.hpp"
#include "Instrumentor.h"

void test1()
{
	int value = 0;
	{
		Timer t("Time took");
		for (int i = 0; i < 2000000; ++i)
		{
			value++;
		}
	}
	std::cout << value << std::endl;
}

void sharedPtrTest()
{
	struct Vector2
	{
		float x;
		float y;
	};

	constexpr int C_SIZE = 20000;
	{
		Timer t("Make shared");
		std::array<std::shared_ptr<Vector2>, C_SIZE> sharedPtrs;
		for (int i = 0; i < C_SIZE; ++i)
		{
			sharedPtrs[i] = std::make_shared<Vector2>();
		}
	}
	{
		Timer t("New shared");
		std::array<std::shared_ptr<Vector2>, C_SIZE> sharedPtrs;
		for (int i = 0; i < C_SIZE; ++i)
		{
			sharedPtrs[i] = std::shared_ptr<Vector2>(new Vector2);
		}
	}
	{
		Timer t("Make unique");
		std::array<std::unique_ptr<Vector2>, C_SIZE> ptrs;
		for (int i = 0; i < C_SIZE; ++i)
		{
			ptrs[i] = std::make_unique<Vector2>();
		}
	}
}

void function1()
{
	// InstrumentationTimer timer("function1");
	// PROFILE_SCOPE("function1");
	PROFILE_FUNCTION();
	for (int i = 0; i < 1000; i ++)
	{
		std::cout << "Hello world #" << i << std::endl;
	}
}

void function1(const int value)
{
	// InstrumentationTimer timer("function2");
	// PROFILE_SCOPE("function2");
	PROFILE_FUNCTION();

	for (int i = 0; i < 1000; i ++)
	{
		std::cout << "Hello world #" << i + value << std::endl;
	}
}

void runBenchMark()
{
	// InstrumentationTimer timer("runBenchMark");
	// PROFILE_SCOPE("runBenchMark");
	PROFILE_FUNCTION();
	std::cout << "Running BenchMark\n";

	function1();
	function1(2);

	std::thread t(
		[]()
		{
			function1(3);
		}
	);
	std::thread t2(
		[]()
		{
			function1();
		}
	);
	t2.join();
	t.join();

}

int main()
{
	Instrumentor::get().beginSession("Main");
	runBenchMark();
	Instrumentor::get().endSession();
}
